<!DOCTYPE html>

<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->

<!-- Head BEGIN -->
<head>
    <meta charset="utf-8">
    <title><?php echo $this->obj->getValidateMessage('menu-5-1'); ?></title>
    <?php echo $this->view->getPartial('layouts/_meta') ?>
</head>
<!-- Head END -->

<!-- Body BEGIN -->
<body class="ecommerce">

<!-- BEGIN TOP BAR -->
<?php echo $this->view->getPartial('layouts/_header') ?>
<!-- Header END -->

<div class="main">
    <div class="container">
        <!-- BEGIN SIDEBAR & CONTENT -->
        <div class="row margin-bottom-40">
            <!-- BEGIN CONTENT -->
            <div class="col-md-12 col-sm-12">
                <h1><?php echo $this->obj->getValidateMessage('menu-5-1'); ?></h1>
                <div class="goods-page">
                    <div class="goods-data clearfix">
                        <div class="table-wrapper-responsive">
                            <table class="order-table">
                                <tbody class="order-table-header">
                                <tr>
                                    <th class="goods-page-description"><?php echo $this->obj->getValidateMessage('shangpin'); ?></th>
                                    <th class="goods-page-price"><?php echo $this->obj->getValidateMessage('danjia'); ?></th>
                                    <th class="goods-page-product-number"><?php echo $this->obj->getValidateMessage('number'); ?></th>
                                    <th class="goods-page-size"><?php echo $this->obj->getValidateMessage('chengjiaozongjia'); ?></th>
                                    <th class="goods-page-quantity"><?php echo $this->obj->getValidateMessage('zhuangtai'); ?></th>
                                </tr>
                                </tbody>
                            </table>

                            <?php if (isset($page) && count($page->items) > 0) { ?>
                                <?php foreach ($page->items as $order) { ?>
                                    <div class="margin10 border">
                                        <table class="order-table">

                                            <tbody class="order-table-title">
                                            <tr>
                                                <td colspan="5" class="text-left">
                                                    <span class="margin-left-20">
                                                        <?php echo date('Y-m-d', strtotime($order['create_time'])); ?>　
                                                        <a href="/order/detail/<?php echo $order['id']; ?>"><?php echo $this->obj->getValidateMessage('dingdanhao'); ?>：<?php echo $order['order_no']; ?></a>　


                                                        <?php if ($order['isShowExpiretime']) { ?>
                                                            <span data-expiretime="<?php echo $order['expire_time']; ?>"
                                                                  data-id="<?php echo $order['id']; ?>"
                                                                  class="remainTime"></span>
                                                        <?php } ?>

                                                        <?php if ($order['isShowTotalprice']) { ?>
                                                            <?php echo $this->obj->getValidateMessage('chengjiaozongjia'); ?>：<?php echo $this->currency . $order['final_price']; ?>
                                                        <?php } ?>


                                                        <?php if ($order['isShowPayAndCancledButtons']) { ?>
                                                            <em class="pull-right font-normal">
                                                                <a href="/order/payment/<?php echo $order['id']; ?>"><?php echo $this->obj->getValidateMessage('to-pay'); ?></a>
                                                                <a style="cursor: pointer"
                                                                   onclick="cancle_order(<?php echo $order['id']; ?>);return false;"><?php echo $this->obj->getValidateMessage('order-cancel'); ?></a>
                                                            </em>
                                                        <?php } ?>


                                                        <?php if ($order['isShowRefundButton']) { ?>
                                                            <em class="pull-right font-normal">
                                                                <a style="cursor: pointer"
                                                                   onclick="refund_order(<?php echo $order['id']; ?>);return false;"><?php echo $this->obj->getValidateMessage('apply-for-refund'); ?></a>
                                                            </em>
                                                        <?php } ?>


                                                        <?php if ($order['isShowOverExpired']) { ?>
                                                            <em class="pull-right font-normal">
                                                                <?php echo $this->obj->getValidateMessage('order-failure'); ?>
                                                            </em>
                                                        <?php } ?>

                                                        <?php if ($order['isShowCancled']) { ?>
                                                            <em class="pull-right font-normal">
                                                                <?php echo $this->obj->getValidateMessage('order-cancled'); ?>
                                                            </em>
                                                        <?php } ?>

                                                        <?php if ($order['isShowRefundStatus']) { ?>
                                                            <em class="pull-right font-normal">
                                                                <?php echo $order['isShowRefundStatus']; ?>
                                                            </em>
                                                        <?php } ?>


                                                    </span>
                                                </td>
                                            </tr>
                                            </tbody>

                                            <?php foreach ($order['orderdetails'] as $orderdetail) { ?>
                                                <tbody>
                                                <tr>
                                                    <td class="text-left">
                                                    <span class="margin-left-20"><a
                                                                href="/product/detail/<?php echo $orderdetail['product_detail_id']; ?>"><img
                                                                    class="w80"
                                                                    src="<?php echo \Asa\Erp\Util::getCorrentImgUrl($this->file_prex . $orderdetail['picture']); ?>"
                                                                    alt="<?php echo $orderdetail['product_name']; ?>"
                                                                    title="<?php echo $orderdetail['product_name']; ?>"></a></span>
                                                    </td>
                                                    <td class="goods-page-price">
                                                        <strong><span><?php echo $this->currency; ?></span><?php echo $orderdetail['price']; ?>
                                                        </strong></td>
                                                    <td class="product-number"><?php echo $orderdetail['number']; ?></td>
                                                    <td class="goods-page-total">
                                                        <strong><span><?php echo $this->currency; ?></span><em><?php echo $orderdetail['payment_amount']; ?></em></strong>
                                                    </td>
                                                    <td class="product-number"><?php echo $order['order_status']; ?></td>
                                                </tr>
                                                </tbody>
                                            <?php } ?>

                                        </table>
                                    </div>
                                <?php } ?>
                            <?php } else { ?>
                                <p class="text-center order-null"><?php echo $this->obj->getValidateMessage('order-empty'); ?></p>
                            <?php } ?>


                            <!-- BEGIN PAGINATOR -->
                            <?php if ($page->total_pages > 1) { ?>
                                <div class="page_margin pull-right">
                                    <ul class="pagination ">
                                        <li class="<?php echo $page->current <= 1 ? 'disabled' : ''; ?>"><a
                                                    href="<?php echo $this->url->get('order/list', ['page' => $page->before]); ?>">&laquo;</a>
                                        </li>
                                        <?php for ($i = 1; $i <= $page->total_pages; $i++) { ?>
                                            <li class="<?php echo $page->current == $i ? 'active' : ''; ?>"><a
                                                        href="<?php echo $this->url->get('order/list', ['page' => $i]); ?>"><?php echo $i; ?></a>
                                            </li>
                                        <?php } ?>
                                        <li class="<?php echo $page->current >= $page->total_pages ? 'disabled' : ''; ?>">
                                            <a href="<?php echo $this->url->get('order/list', ['page' => $page->next]); ?>">&raquo;</a>
                                        </li>
                                    </ul>
                                </div>
                            <?php } ?>
                            <!-- END PAGINATOR -->


                        </div>


                    </div>

                </div>
            </div>
            <!-- END CONTENT -->
        </div>
        <!-- END SIDEBAR & CONTENT -->

    </div>
</div>

<!-- BEGIN PRE-FOOTER -->
<?php echo $this->view->getPartial('layouts/_footer') ?>
<!-- END FOOTER -->

<script>
    //支付剩余时间倒计时
    $(function () {
        // 定义当前时间
        var now = new Date();
        // 首先判断有几个是需要轮询的订单，也就是状态为待付款的
        $('.remainTime').each(function () {
            // 单独统计每个订单的有效期
            let end = new Date($(this).attr('data-expiretime'));
            // 两个时间相减,得到的是毫秒ms
            let result = Math.floor(end - now) / 1000;
            // 取出当前对象
            let _this = $(this);
            // 定时器调度对象
            let interval = setInterval(function () {
                if (result > 1) {
                    result = result - 1;
                    // 计算出相差天数
                    let days = Math.floor(result / (24 * 3600));
                    // 计算出小时数
                    let leave1 = result % (24 * 3600);    //计算天数后剩余的毫秒数
                    let hours = Math.floor(leave1 / 3600);
                    //计算相差分钟数
                    let leave2 = leave1 % 3600;        //计算小时数后剩余的毫秒数
                    let minutes = Math.floor(leave2 / 60);
                    //计算相差秒数
                    let leave3 = leave2 % 60;      //计算分钟数后剩余的毫秒数
                    let seconds = Math.round(leave3);
                    // 写入dom
                    // 判断是否过期
                    _this.html("<?php echo $this->obj->getValidateMessage('remain-time'); ?>：" + days + "<?php echo $this->obj->getValidateMessage('days'); ?>" + hours + "<?php echo $this->obj->getValidateMessage('hours'); ?>" + minutes + "<?php echo $this->obj->getValidateMessage('minutes'); ?>" + seconds + "<?php echo $this->obj->getValidateMessage('seconds'); ?>");
                } else {
                    // 这里可以添加倒计时结束后需要执行的事件
                    window.clearInterval(interval);
                    // 下面的逻辑已经交给后台队列处理了，暂时废弃。
                    // // Todo订单失效后的一些列操作：更改订单状态的同时回库存，如果前台还保留此页面，那就做到实时，否则就异步处理。
                    // // ajax取消订单
                    // $.post('/order/cancle/' + _this.attr('data-id'), {}, function (response) {
                    //     // 如果没有错误，就删除右侧节点
                    //     if (response.messages.length === 0) {
                    //         _this.next().remove();
                    //     }
                    // }, 'json');
                }
            }, 1000);
        });
    });
</script>

</body>
<!-- END BODY -->
</html>